﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Threading;
using System.Drawing;
using System.IO;
using System.Resources;
namespace Cinser.Common.Wpf.Controls
{
     
    /// <summary>
    /// CrWaitControl.xaml 的交互逻辑
    /// </summary>
    public partial class CrWaitControl :Window
    {
        public Action WorkMethod;
        public CrWaitControl(Action workMethod)
        {
            InitializeComponent();
            this.WorkMethod = workMethod;
            this.Topmost = true;
            this.ShowDialog();
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            //设置等待GIF图标
            ResourceManager resourceManager = Cinser.Common.Wpf.Resource.ResourceManager; // Properties.Resources;
            Bitmap gifSrcWait = (Bitmap)resourceManager.GetObject("wait2");
            MemoryStream ms = new MemoryStream();
            gifSrcWait.Save(ms, System.Drawing.Imaging.ImageFormat.Gif);
            gif.SetSource(ms);

            Thread th = new Thread(new ThreadStart(Work));
            th.IsBackground = true;
            th.Start();
        }
        private void Work()
        {
            if (WorkMethod != null)
            {
                WorkMethod();
            }
            this.Dispatcher.Invoke(new Action(() => {
                this.Close();
            }));
        }
    }
}
